﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>无标题页</title>
    <script type="text/javascript">
    function initEvent()
    {
        var inputs = document.getElementsByTagName("input");
        for(var i=0;i<inputs.length;i++)
        {
            var input = inputs[i];
            if(input.type == "text")
            {
            // input.onfocus = watchFocus;
               input.onfocus = inputOnfocus;
               input.onblur = inputOnblur;
            }
        }
    }
    
    function initEvent2()  //用匿名函数写的..
    {
        var inputs = document.getElementsByTagName("input");
        for(var i=0;i<inputs.length;i++)
        {
            var input = inputs[i];
            if(input.type == "text")
            {
            // input.onfocus = watchFocus;
               input.onfocus = function(){this.style.background = "yellow";};
               input.onblur = function(){this.style.background = "white";};
            }
        }
    }
    
    function inputOnfocus()
    {
        this.style.background = "yellow";
    }
    
    function inputOnblur()
    {
        this.style.background = "white";
    }
    
 /*   function watchFocus()
    {
        var inputs = document.getElementsByTagName("input");
        for(var i=0;i<inputs.length;i++)
        {
            var input = inputs[i];
            if(input == this)
            {
                input.style.background = "yellow";
            }
            else
            {
                input.style.background = "white";
            }
        }
    }*/
    </script>
</head>
<body onload="initEvent()">
<input type="text" /><br />
<input type="text" /><br />
<input type="text" /><br />
<input type="text" /><br />
<input type="button" value="sad" /><br />
</body>
</html>
